package org.argus.management.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.argus.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.argus.management.domain.Role;
import org.argus.management.system.model.RoleMenuBindReq;
import org.argus.management.system.model.RoleSearchReq;
import org.argus.management.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author 刘文/Cliff Liu
 * @Date 2024/6/2
 */
@Api("角色管理")
@RestController
@RequestMapping(value = "/system/v1/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation("角色添加")
    public R<Boolean> add() {
        return R.ok();
    }

    @ApiOperation("保存角色")
    @PostMapping("/save")
    public R<Boolean> save(@RequestBody Role role) {
        roleService.save(role);
        return R.ok(Boolean.TRUE);
    }

    @ApiOperation("修改角色状态")
    @PutMapping(value = "/role-status")
    public R<Boolean> modifyStatus(@RequestBody Role role) {
        roleService.updateStatus(role);
        return R.ok(Boolean.TRUE);
    }

    @ApiOperation("角色删除")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        roleService.delete(id);
        return R.ok(Boolean.TRUE);
    }

    @ApiOperation("角色菜单ID列表")
    @GetMapping("/role-menu-ids/{id}")
    public R<List<Long>> roleMenuIds(@PathVariable("id") Long id) {
        return R.ok(roleService.roleMenuIds(id));
    }

    @ApiOperation("角色查找")
    @GetMapping("/search")
    public R<Page<Role>> search(RoleSearchReq req, Page page) {
        return R.ok(roleService.search(req, page));
    }

    @ApiOperation("获取所有角色列表")
    @GetMapping("/list-all-role")
    public R<List<Role>> listAllRole() {
        return R.ok(roleService.listAllRole());
    }

    @ApiOperation("保存角色/菜单绑定")
    @PostMapping("/role-menu")
    public R<Boolean> roleMenuBind(@RequestBody @Valid RoleMenuBindReq req) {
        roleService.roleMenuBind(req);
        return R.ok(Boolean.TRUE);
    }
}
